//
//  MainMenuLayer.m
//  MinusTheBox
//
//  Created by Chi Ho Chiu on 12/4/12.
//  Copyright 2012 Individual. All rights reserved.
//

#import "MainMenuLayer.h"
#import "SelectLevelScene.h"


@implementation MainMenuLayer

// Helper class method that creates a Scene with the HelloWorldLayer as the only child.
+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	MainMenuLayer *layer = [MainMenuLayer node];
	
	// add layer as a child to scene
	[scene addChild: layer];
	
	// return the scene
	return scene;
}

-(id)init
{
	if (self = [super init])
	{
		CGSize winSize = [[CCDirector sharedDirector] winSize];
		
		//Add Background Image
		CCSprite *bg = [CCSprite spriteWithFile:@"mainmenu_bg.png"];
		bg.position = ccp(winSize.width/2, winSize.height/2);
		[self addChild:bg];
		
		//Add Title
		CCLabelBMFont *titleLabel = [CCLabelBMFont labelWithString:@"Box Chain" fntFile:@"Dakota_white_32.fnt"];
		titleLabel.position = ccp(winSize.width/2, winSize.height/2 + 140 );
		[self addChild:titleLabel];
		
		//Add Menu Item 
        CCLabelBMFont *startFont = [CCLabelBMFont labelWithString:@"Start" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *startItem = [CCMenuItemLabel itemWithLabel:startFont target:self selector:@selector(startItemClicked:)];
        
        CCLabelBMFont *optionFont = [CCLabelBMFont labelWithString:@"Option" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *optionItem = [CCMenuItemLabel itemWithLabel:optionFont target:self selector:@selector(optionItemClicked:)];

        CCMenu *menu = [CCMenu menuWithItems:startItem, optionItem, nil];
        [menu alignItemsVertically];
        
        [menu setPosition: ccp( winSize.width/2, winSize.height/2)];
        [self addChild:menu];
	}
	
	return self;
}

-(void) dealloc
{
	[super dealloc];
}

#pragma mark - Menu Item Selector
-(void) startItemClicked:(CCMenuItem *)menuItem
{
	[[CCDirector sharedDirector] pushScene:[SelectLevelScene node]];
}

-(void) optionItemClicked:(CCMenuItem *)menuItem
{

}
@end
